
"""
dump_all(data,yaml对象) ：将Python对象转化为yaml格式并且输出到yaml文件中 ，支持多个Python对象
"""

import yaml

data1 = {
    'languages': ['Ruby', 'Perl', 'Python'],
    'websites': {'YAML': 'yaml.org', 'Ruby': 'ruby-lang.org', 'Python': 'python.org', 'Perl': 'use.perl.org'}
}


data2 = {
    'color':['红色','蓝色','绿色'],
    'languages': ['Ruby', 'Perl', 'Python'],
    'websites': {'YAML': 'yaml.org', 'Ruby': 'ruby-lang.org', 'Python': 'python.org', 'Perl': 'use.perl.org'}
}

def save_yaml(data,filename):
    with open(filename,mode='w',encoding='utf-8') as f:
        yaml.dump_all(data,f,allow_unicode=True,sort_keys=False)

if __name__ == '__main__':
    save_yaml([data1,data2],'demo3.yaml')